package com.mindbook.vip.gawxchatinfo.config.shiro;

import org.apache.shiro.web.filter.authc.UserFilter;
import org.apache.shiro.web.util.WebUtils;
import org.springframework.stereotype.Component;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @NAME: wxb
 * @DATE: 2022/5/1
 **/
@Component
public class SessionCheckFilter extends UserFilter {

    @Override
    protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws Exception {

        HttpServletRequest httpRequest = (HttpServletRequest) request;
        HttpServletResponse httpResponse = (HttpServletResponse) response;

        //解决跨域问题
        if ("OPTIONS".equals(httpRequest.getMethod())){
            httpResponse.setStatus(HttpServletResponse.SC_NO_CONTENT);;
            return true;
        }

        return false;
    }
}
